import _ from "lodash";
export default {
	namespaced: true,
	state: {
		cart_info: {}, // 购物车信息
		cart_qty: {},
		order_info: {}, // 购物车结算信息
		coupons: {}, // 可用优惠券
		discount: [], // 可用折扣信息
		is_cust_sum: false, // 是否选择就餐人数
		payment: [], // 支付信息
		client_sn: '', // 当前支付订单号
		order_id: '' // 当前订单号
	},
	// 同步操作 调用方法 commit
	mutations: {
		// 轮播图
		setCartInfo (state, val) {
			var product_noArr = []
			_.each(val, item => {
				product_noArr.push(item.product_no)
				state.cart_qty[item.product_no] = item.qty
			})
			for(let i in state.cart_qty){
				if(!product_noArr.includes(i)){
					state.cart_qty[i] = false
				}
			}
			state.cart_info = val
		},
		// 产品分类和产品相关
		setOrderInfo (state, val) {
			state.order_info = val
		},
		// 可用优惠券
		setCoupons (state, val) {
			state.coupons = val
		},
		// 可用折扣
		setDiscount (state, val) {
			state.discount = val
		},
		// 是否选择就餐人数
		setIsCustSum (state, val) {
			state.is_cust_sum = val
		},
		// 支付详情
		setPayment (state, val) {
			state.payment = val
		},
		// 设置整个订单信息
		setOrderData(state, val) {
			var product_noArr = []
			_.each(val.cart_info, item => {
				product_noArr.push(item.product_no)
				state.cart_qty[item.product_no] = item.qty
			})
			for(let i in state.cart_qty){
				if(!product_noArr.includes(i)){
					state.cart_qty[i] = false
				}
			}
			state.cart_info = val.cart_info
			state.order_info = val.order_info
			// state.coupons = val.coupons
			state.discount = val.discount
			state.is_cust_sum = val.is_cust_sum
			state.payment = val.payment
		},
		// 保存商户订单号
		setClientSn (state, val) {
			state.client_sn = val
		},
		setOrderId (state, val) {
			state.order_id = val
		}
	},
	// 异步操作
	actions: {
	}
};
